(function(){
	var script = document.createElement('script');
	script.type = 'text/javascript';
	if(window.page == 0) {
		script.src = 'https://maps.googleapis.com/maps/api/js?key=AIzaSyAuBWJtxkiuJGQ_IpfGxJJFAnoLSE59DVo&sensor=false&'
			+ 'callback=initialize&language=zh-CN&&libraries=places';
	}else {
		script.src = 'https://maps.googleapis.com/maps/api/js?key=AIzaSyAuBWJtxkiuJGQ_IpfGxJJFAnoLSE59DVo&sensor=false&'
			+ 'callback=initialize&language=zh-CN&libraries=geometry';
	}
	document.body.appendChild(script);
	
})(jQuery);


function initialize() {
	navigator.geolocation.getCurrentPosition(function(position){
//		var initialLoc = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
		var initialLoc = new google.maps.LatLng(31.2072103, 121.58700499999998);
		var mapOptions = {
			zoom: 16,
			mapTypeId: google.maps.MapTypeId.ROADMAP,
			center: initialLoc,
			panControl : true,
			zoomControl : true,
			scaleControl : false,
			streetViewControl : false,
			overviewMapControl : false,
			mapTypeControl : false
		};
		var map1 = window.map = new google.maps.Map(document.getElementById("mapContainer"), mapOptions);

		var shadowIcon = {
			url: "../images/manMarkerShadow.png",
			scaledSize: new google.maps.Size(80,40),
			anchor: new google.maps.Point(20,40)
		};
		var icon = {
			url:"../images/manMarker.png",
			scaledSize: new google.maps.Size(40,40)
		};
		window.markerPassenger = new google.maps.Marker({
			visible: true,
			position: initialLoc,
			map: map1,
			icon: icon,
			shadow: shadowIcon
		});
		createControl(initialLoc);
		window.customer.latitude = position.coords.latitude;
		window.customer.longitude = position.coords.longitude;
		window.passengerLatLng = initialLoc;
	});		
}

function createControl(initialLoc){
	var controlUI = document.createElement("div");
	controlUI.style.marginLeft = '25px';
	controlUI.style.marginTop = '10px';
	var uiImg = document.createElement("img");
	uiImg.setAttribute("src", "../images/home.ico");
	uiImg.setAttribute("height", "40");
	uiImg.setAttribute("width", "40");
	controlUI.appendChild(uiImg);
	google.maps.event.addDomListener(controlUI, "click", function(){
		window.map.setCenter(initialLoc);
	});
	map.controls[google.maps.ControlPosition.LEFT_TOP].push(controlUI);
}